package com.wutuo.aggragation.expire.dao;

import cn.apestar.core.database.BaseMapper;
import com.wutuo.aggragation.expire.domain.ExpireManagementLatest;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

public interface ExpireManagementLatestMapper extends BaseMapper {
    @Delete({
            "delete from wt_expire_management_latest",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into wt_expire_management_latest (id, create_by, ",
            "create_date, update_by, ",
            "update_date, remarks, ",
            "del_flag, institution_id, ",
            "roster_id, sms_date, ",
            "expire_management_id)",
            "values (#{id,jdbcType=BIGINT}, #{createBy,jdbcType=BIGINT}, ",
            "#{createDate,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=BIGINT}, ",
            "#{updateDate,jdbcType=TIMESTAMP}, #{remarks,jdbcType=VARCHAR}, ",
            "#{delFlag,jdbcType=CHAR}, #{institutionId,jdbcType=BIGINT}, ",
            "#{rosterId,jdbcType=BIGINT}, #{smsDate,jdbcType=TIMESTAMP}, ",
            "#{expireManagementId,jdbcType=BIGINT})"
    })
    @SelectKey(before = false, keyProperty = "id", resultType = Long.class, statement = "SELECT LAST_INSERT_ID() AS id")
    int insert(ExpireManagementLatest record);

    @InsertProvider(type = ExpireManagementLatestSqlProvider.class, method = "insertSelective")
    int insertSelective(ExpireManagementLatest record);

    @Select({
            "select",
            "id, create_by, create_date, update_by, update_date, remarks, del_flag, institution_id, ",
            "roster_id, sms_date, expire_management_id",
            "from wt_expire_management_latest",
            "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_by", property = "updateBy", jdbcType = JdbcType.BIGINT),
            @Result(column = "update_date", property = "updateDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "remarks", property = "remarks", jdbcType = JdbcType.VARCHAR),
            @Result(column = "del_flag", property = "delFlag", jdbcType = JdbcType.CHAR),
            @Result(column = "institution_id", property = "institutionId", jdbcType = JdbcType.BIGINT),
            @Result(column = "roster_id", property = "rosterId", jdbcType = JdbcType.BIGINT),
            @Result(column = "sms_date", property = "smsDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "expire_management_id", property = "expireManagementId", jdbcType = JdbcType.BIGINT)
    })
    ExpireManagementLatest selectByPrimaryKey(Long id);

    @UpdateProvider(type = ExpireManagementLatestSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(ExpireManagementLatest record);

    @Update({
            "update wt_expire_management_latest",
            "set create_by = #{createBy,jdbcType=BIGINT},",
            "create_date = #{createDate,jdbcType=TIMESTAMP},",
            "update_by = #{updateBy,jdbcType=BIGINT},",
            "update_date = #{updateDate,jdbcType=TIMESTAMP},",
            "remarks = #{remarks,jdbcType=VARCHAR},",
            "del_flag = #{delFlag,jdbcType=CHAR},",
            "institution_id = #{institutionId,jdbcType=BIGINT},",
            "roster_id = #{rosterId,jdbcType=BIGINT},",
            "sms_date = #{smsDate,jdbcType=TIMESTAMP},",
            "expire_management_id = #{expireManagementId,jdbcType=BIGINT}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(ExpireManagementLatest record);

    @Select({
            "select",
            "id, create_by, create_date, update_by, update_date, remarks, del_flag, institution_id, ",
            "roster_id, sms_date, expire_management_id",
            "from wt_expire_management_latest",
            "where roster_id = #{rosterId,jdbcType=BIGINT} and institution_id = #{institutionId} and del_flag = '1' "
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_by", property = "updateBy", jdbcType = JdbcType.BIGINT),
            @Result(column = "update_date", property = "updateDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "remarks", property = "remarks", jdbcType = JdbcType.VARCHAR),
            @Result(column = "del_flag", property = "delFlag", jdbcType = JdbcType.CHAR),
            @Result(column = "institution_id", property = "institutionId", jdbcType = JdbcType.BIGINT),
            @Result(column = "roster_id", property = "rosterId", jdbcType = JdbcType.BIGINT),
            @Result(column = "sms_date", property = "smsDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "expire_management_id", property = "expireManagementId", jdbcType = JdbcType.BIGINT)
    })
    ExpireManagementLatest getByRosterIdAndInstitutionId(@Param("rosterId") Long rosterId, @Param("institutionId") Long institutionId);

    @Select({
            "select",
            "id, create_by, create_date, update_by, update_date, remarks, del_flag, institution_id, ",
            "roster_id, sms_date, expire_management_id",
            "from wt_expire_management_latest",
            "where roster_id = #{rosterId,jdbcType=BIGINT} and del_flag = '1' "
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_by", property = "updateBy", jdbcType = JdbcType.BIGINT),
            @Result(column = "update_date", property = "updateDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "remarks", property = "remarks", jdbcType = JdbcType.VARCHAR),
            @Result(column = "del_flag", property = "delFlag", jdbcType = JdbcType.CHAR),
            @Result(column = "institution_id", property = "institutionId", jdbcType = JdbcType.BIGINT),
            @Result(column = "roster_id", property = "rosterId", jdbcType = JdbcType.BIGINT),
            @Result(column = "sms_date", property = "smsDate", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "expire_management_id", property = "expireManagementId", jdbcType = JdbcType.BIGINT)
    })
    ExpireManagementLatest getByRosterId(@Param("rosterId") Long rosterId);

    @Update({
            "update wt_expire_management_latest",
            "set update_by = #{updateBy,jdbcType=BIGINT},",
            "update_date = #{updateDate,jdbcType=TIMESTAMP},",
            "expire_management_id = #{expireManagementId,jdbcType=BIGINT}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateExipreManagementId(ExpireManagementLatest record);

    @Update({
            "update wt_expire_management_latest",
            "set update_by = #{updateBy,jdbcType=BIGINT},",
            "update_date = #{updateDate,jdbcType=TIMESTAMP},",
            "sms_date = #{smsDate}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateSmsDate(ExpireManagementLatest record);
}